/**
 * XSAN 错误类型定义
 */
#ifndef XSAN_ERROR_H
#define XSAN_ERROR_H

/**
 * XSAN 错误代码类型
 */
typedef enum {
    XSAN_SUCCESS = 0,
    XSAN_OK = 0,                      /* XSAN_OK 作为 XSAN_SUCCESS 的别名 */
    XSAN_ERROR_INVALID_PARAM = -1,
    XSAN_ERROR_NO_MEMORY = -2,
    XSAN_ERROR_IO = -3,
    XSAN_ERROR_NOT_FOUND = -4,
    XSAN_ERROR_ALREADY_EXISTS = -5,
    XSAN_ERROR_PERMISSION = -6,
    XSAN_ERROR_BUSY = -7,
    XSAN_ERROR_TIMEOUT = -8,
    XSAN_ERROR_NOT_SUPPORTED = -9,
    XSAN_ERROR_DEVICE_ERROR = -10,
    XSAN_ERROR_NETWORK = -11,
    XSAN_ERROR_CLUSTER = -12,
    XSAN_ERROR_NETWORK_DOWN = -13,    /* 网络连接不可用 */
    XSAN_ERROR_CONNECTION_LOST = -14, /* 连接已断开 */
    XSAN_ERROR_SYSTEM = -15,          /* 系统错误 */
    XSAN_ERROR_GENERIC = -16,         /* 通用错误 */
    XSAN_ERROR_NOT_INITIALIZED = -17, /* 模块未初始化 */
    XSAN_ERROR_THREAD_CONTEXT = -18,  /* 线程上下文错误 */
    XSAN_ERROR_INSUFFICIENT_SPACE = -19, /* 空间不足 */

    /* 存储相关错误 */
    XSAN_ERROR_STORAGE_IO = -40,
    XSAN_ERROR_DEVICE_NOT_FOUND = -41,
    XSAN_ERROR_VOLUME_NOT_FOUND = -42,
    
    /* 配置相关错误 */
    XSAN_ERROR_CONFIG_PARSE = -60,
    XSAN_ERROR_CONFIG_INVALID = -61,
    
    /* 任务相关错误 */
    XSAN_ERROR_TASK_FAILED = -80,
    XSAN_ERROR_TASK_CANCELLED = -81,
    
    /* 测试相关错误 */
    XSAN_ERROR_TEST_VERIFY_FAILED = -90,
    
    /* 虚拟化相关错误 */
    XSAN_ERROR_VM_NOT_FOUND = -100,
    
    /* 存储相关错误 */
    XSAN_ERROR_STORAGE_GENERIC = -120,
    XSAN_ERROR_OUT_OF_BOUNDS = -121,
    XSAN_ERROR_UNMAPPED_LBA = -122,
    XSAN_ERROR_TOO_MANY_EXTENTS = -123,
    XSAN_ERROR_RESOURCE_UNAVAILABLE = -124,
    XSAN_ERROR_INVALID_PARAM_ALIGNMENT = -125,
    XSAN_ERROR_INVALID_PARAM_SIZE = -126,
    
    /* 协议相关错误 */
    XSAN_ERROR_PROTOCOL_GENERIC = -140,
    XSAN_ERROR_INVALID_MSG_TYPE = -141,
    
    /* 复制相关错误 */
    XSAN_ERROR_REPLICATION_UNAVAILABLE = -160,
    
    /* 内部错误 */
    XSAN_ERROR_INTERNAL = -180,
    XSAN_ERROR_OUT_OF_MEMORY = -181,
    
    /* 未实现功能错误 */
    XSAN_ERROR_NOT_IMPLEMENTED = -999,

    XSAN_ERROR_UNKNOWN = -1000
} xsan_error_t;

/**
 * 将系统errno转换为xsan_error_t类型
 */
xsan_error_t xsan_error_from_errno(int err);

/**
 * 获取错误描述字符串
 */
const char *xsan_error_to_string(xsan_error_t err);

#endif /* XSAN_ERROR_H */
